import time
import keyboard
import pyperclip
from pasteWithKeybord import paste

# 复制粘贴快捷键
key1 = 'command'
key2 = 'c'
# 触发粘贴的快捷键 (双击)
key3 = 'esc'

key1_down = False
key2_down = False
key3_down = False
key3_down_time = 0

def callback(key):
    # print(key.name)
    global key1_down
    global key2_down
    global key3_down
    global key3_down_time

    if key.name == key1 and key.event_type == 'down':
        key1_down = True
    if key.name == key2 and key.event_type == 'down':
        key2_down = True
    if key.name == key1 and key.event_type == 'up':
        key1_down = False
    if key.name == key2 and key.event_type == 'up':
        key2_down = False

    # 满足快捷键
    if key1_down and key2_down:
        pass
        # time.sleep(0.1)
        # clip = pyperclip.paste()

    if key.name == key3 and key.event_type == 'down':
        if time.time() - key3_down_time < 0.5:
            time.sleep(0.4)
            clip = pyperclip.paste()
            paste(clip)
        key3_down_time = time.time()
    

keyboard.hook(callback)

print("开始监听, 输入 q 退出")

while True:
    userInput = input()
    if userInput == 'q': break

